package control;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Vector;

/**
 * This program reads a text file line by line and print to the console. It uses
 * FileOutputStream to read the file.
 * 
 */
public class ReadFile  {
	private Vector<String> result = new Vector<String>();
	private Vector<Integer> effect = new Vector<Integer>();
	public int lineCount =0;
	private String filePath;
	
	 public ReadFile(String f) {
		 this.filePath = f;
	}
	public Vector<String> getResult(){
		 return result;
	 }
	
	 public Vector<Integer> getEffect(){
		 return effect;
	 }
	 
	 public void readItemFile(){	
		 try {
			 /**Read Chinese*/
			 String encoding = "UTF-8"; 
			 InputStreamReader read = new InputStreamReader(ReadFile.class.getResourceAsStream(filePath), encoding);
				
		     BufferedReader bufferedReader = new BufferedReader(read);
		     String lineTXT = null;
		     lineCount = 0;
		     while ((lineTXT = bufferedReader.readLine()) != null) {
		     	if(lineCount != 3){
			          
		                 	result.add(lineTXT);
		                 	lineCount++;
		               }
		         else{
		         		effect.add(Integer.valueOf(lineTXT));
		         		lineCount=0;
		         }
		         
		     }
		 }
		 catch(Exception e) {
			 System.out.println("Error!");
			 e.printStackTrace();
		 }
	 }
	 public void readMCFile() {	 
		 try {
			 /**Read Chinese*/
			 String encoding = "UTF-8"; 
			 InputStreamReader read = new InputStreamReader(ReadFile.class.getResourceAsStream(filePath), encoding);
				
		     BufferedReader bufferedReader = new BufferedReader(read);
		     String lineTXT = null;
		     lineCount = 0;
		     while ((lineTXT = bufferedReader.readLine()) != null) {
				 /**split by "&" for mc now.  */ 
		         if(lineCount != 5){
		               	result.add(lineTXT);
		               	lineCount++;
		             }
		           else{
		           		String[] text = lineTXT.split("&"); 
		               	for (int i = 0; i < text.length; i++) {
		               		
		               	effect.add(Integer.valueOf(text[i]));	
		       
		               	}
		               	lineCount=0;
		           }
		         	
		     }
		 }
		 catch(Exception e) {
			 System.out.println("Error!");
			 e.printStackTrace();
		 }
	 }
	 public void readNormalCardFile() { 
		 try {
			 /**Read Chinese*/
			 String encoding = "UTF-8"; 
			 InputStreamReader read = new InputStreamReader(ReadFile.class.getResourceAsStream(filePath), encoding);
				
		     BufferedReader bufferedReader = new BufferedReader(read);
		     String lineTXT = null;
		    	lineCount = 0;
		     while ((lineTXT = bufferedReader.readLine()) != null) {
				 String[] text = lineTXT.split("&"); 
		    	 for (int i = 0; i < text.length; i++) {
		                if(i==0)
		                	result.add(text[i]);
		                else 
		                	effect.add(Integer.valueOf(text[i]));		               	
		        }
		    	lineCount++;
		     }
		 }
		 catch(Exception e) {
			 System.out.println("Error!");
			 e.printStackTrace();
		 }
	 }
	 
	 
	 public void readEventCardFile(){
		 try{
			 String encoding = "UTF-8";
			 InputStreamReader read = new InputStreamReader(ReadFile.class.getResourceAsStream(filePath), encoding);
		     BufferedReader bufferedReader = new BufferedReader(read);
		     
		     String lineTXT = null;
		     lineCount = 0;
		     while((lineTXT = bufferedReader.readLine()) != null)
		     {
		    	result.add(lineTXT);	 
		    	 } 
		 }
		 catch(Exception e) {
			 System.out.println("Error!");
			 e.printStackTrace();
		 }
	 }
	 

}

